<template>
  <div>
    <el-table
      :data="specsList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="规格编号" >
      </el-table-column>
      <el-table-column prop="specsname" label="规格名称">
      </el-table-column>
      <el-table-column  label="规格属性"> 
            <template v-slot="scoped">
          <div>
            <el-tag v-for="(item,index) in scoped.row.attrs" :key="index">{{item}}</el-tag>
          </div>
        </template>
      </el-table-column>
       <el-table-column  label="状态">
        <template v-slot="scoped">
          <div>
            <el-button type="success" v-if="scoped.row.status == 1"
              >启用</el-button
            >
            <el-button type="info" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column  label="操作">
           <template v-slot="scoped">
          <div>
            <el-button @click="edit(scoped.row.id)">编辑</el-button>
            <el-button @click="del(scoped.row.id)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination background layout="prev, pager, next" :total="specsTotal" :page-size="specsSize" @current-change="changePage">
    </el-pagination>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {specsDel} from "../../../request/api.js"
import {sucessAlert,warningAlert} from "../../../utils/alert"

export default {
  props: [],
  components: {},
  data() {
    return {
        form:{
            specsname:"",
            attrs:"",
            status:1
        }
    };
  },
  computed: {
    ...mapGetters({
      specsList: "specs/list",
      specsTotal: "specs/total",
      specsSize: "specs/size",
    }),
  },
  methods: {
    ...mapActions({
      specsAscyncList: "specs/asyncList",
      specsAscyncTotal:"specs/asyncTotal",
      specsAscyncPage:"specs/asyncPage"
    }),
     changePage(e){
        this. specsAscyncPage(e)
        },
    edit(id){
       this.$emit("update",id) 
    },
    del(id){
        specsDel({id:id}).then(res=>{
            if(res.data.code==200){
               sucessAlert(res.data.msg),
                this.specsAscyncList(),
               this.specsAscyncTotal()
              
            }else{
                warningAlert(res.data.msg)
            }
        })
    }
  },
  mounted() {
    //   this.specsAscyncList();
      this.specsAscyncTotal();
      this.specsAscyncPage(1);
  },
};
</script>
<style scoped>
</style>